#include "CAi.h"

bool CAi::CheckDistance(CRole * pRole1, CRole * pRole2, int d)
{
	if(pRole1->GetID() != pRole2->GetID())
	{
		long x2 = (pRole1->GetMidpoint().x - pRole2->GetMidpoint().x) * (pRole1->GetMidpoint().x - pRole2->GetMidpoint().x);
		long y2 = (pRole1->GetMidpoint().y - pRole2->GetMidpoint().y) * (pRole1->GetMidpoint().y - pRole2->GetMidpoint().y);

		int result = (int)sqrt( (float)(x2 + y2) );
		return (result < d);
	}
	return false;
}

bool CAi::CheckCrash(CRole * pRole1, CRole * pRole2)
{
	if(pRole1->GetID() != pRole2->GetID())
	{
		if( ((pRole1->GetCrashRect().left > pRole2->GetCrashRect().left && pRole1->GetCrashRect().left < pRole2->GetCrashRect().right) ||
			(pRole1->GetCrashRect().right > pRole2->GetCrashRect().left && pRole1->GetCrashRect().right < pRole2->GetCrashRect().right)) &&
			((pRole1->GetCrashRect().top > pRole2->GetCrashRect().top && pRole1->GetCrashRect().top < pRole2->GetCrashRect().bottom) ||
			(pRole1->GetCrashRect().bottom > pRole2->GetCrashRect().top && pRole1->GetCrashRect().bottom < pRole2->GetCrashRect().bottom)) )
		{
			return true;
		}
	}
	return false;
}